<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=11"/>
<meta name="generator" content="Doxygen 1.12.0"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>NeuZephyr: D:/Users/Mgepahmge/Documents/C Program/NeuZephyr/include/NeuZephyr/NeuZephyrCudaErrorHandling.cuh Source File</title>
<link rel="icon" href="NZ_logo2.png" type="image/x-icon" />
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr id="projectrow">
  <td id="projectlogo"><img alt="Logo" src="NZ_logo2.png"/></td>
  <td id="projectalign">
   <div id="projectname">NeuZephyr
   </div>
   <div id="projectbrief">Simple DL Framework</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.12.0 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(function() { codefold.init(0); });
/* @license-end */
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="pages.html"><span>Related&#160;Pages</span></a></li>
      <li><a href="namespaces.html"><span>Namespaces</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
    </ul>
  </div>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(function(){ initResizable(false); });
/* @license-end */
</script>
<div id="nav-path" class="navpath">
  <ul>
<li class="navelem"><a class="el" href="dir_d522931ffa1371640980b621734a4381.html">Users</a></li><li class="navelem"><a class="el" href="dir_a7e6ee1ae3f772c9504a0b543f2027e2.html">Mgepahmge</a></li><li class="navelem"><a class="el" href="dir_e03f57e346cc4845a4c354a35630b169.html">Documents</a></li><li class="navelem"><a class="el" href="dir_231a0482af2b83c895f27ba7fe745141.html">C Program</a></li><li class="navelem"><a class="el" href="dir_0fa7fc3a0dfd304dbfc9dce9f6facfa2.html">NeuZephyr</a></li><li class="navelem"><a class="el" href="dir_e7295b03dab2e9cdf32139bd8ec2e607.html">include</a></li><li class="navelem"><a class="el" href="dir_657344ecc65cfc28732701509f8d8421.html">NeuZephyr</a></li>  </ul>
</div>
</div><!-- top -->
<div id="doc-content">
<div class="header">
  <div class="headertitle"><div class="title">NeuZephyrCudaErrorHandling.cuh</div></div>
</div><!--header-->
<div class="contents">
<div class="fragment"><div class="line"><a id="l00001" name="l00001"></a><span class="lineno">    1</span><span class="preprocessor">#ifndef NEUZEPHYRCUDAERRORHANDLING_CUH</span></div>
<div class="line"><a id="l00002" name="l00002"></a><span class="lineno">    2</span><span class="preprocessor">#define NEUZEPHYRCUDAERRORHANDLING_CUH</span></div>
<div class="line"><a id="l00003" name="l00003"></a><span class="lineno">    3</span><span class="preprocessor">#include &lt;stdexcept&gt;</span></div>
<div class="line"><a id="l00004" name="l00004"></a><span class="lineno">    4</span><span class="preprocessor">#include &lt;cstdio&gt;</span></div>
<div class="line"><a id="l00005" name="l00005"></a><span class="lineno">    5</span><span class="preprocessor">#include &quot;dl_export.cuh&quot;</span></div>
<div class="line"><a id="l00006" name="l00006"></a><span class="lineno">    6</span> </div>
<div class="line"><a id="l00007" name="l00007"></a><span class="lineno">    7</span><span class="preprocessor">#ifdef __CUDACC__</span></div>
<div class="line"><a id="l00008" name="l00008"></a><span class="lineno">    8</span><span class="preprocessor">#include &lt;cuda_runtime.h&gt;</span></div>
<div class="line"><a id="l00009" name="l00009"></a><span class="lineno">    9</span> </div>
<div class="line"><a id="l00010" name="l00010"></a><span class="lineno">   10</span><span class="keyword">namespace </span>nz {</div>
<div class="foldopen" id="foldopen00062" data-start="{" data-end="};">
<div class="line"><a id="l00062" name="l00062"></a><span class="lineno"><a class="line" href="classnz_1_1_cuda_exception.html">   62</a></span>    <span class="keyword">class </span>DL_API <a class="code hl_class" href="classnz_1_1_cuda_exception.html">CudaException</a> final : <span class="keyword">public</span> std::runtime_error {</div>
<div class="line"><a id="l00063" name="l00063"></a><span class="lineno">   63</span>    <span class="keyword">public</span>:</div>
<div class="line"><a id="l00064" name="l00064"></a><span class="lineno">   64</span>        <a class="code hl_class" href="classnz_1_1_cuda_exception.html">CudaException</a>(<span class="keyword">const</span> <span class="keywordtype">char</span>* file, <span class="keywordtype">int</span> line,</div>
<div class="line"><a id="l00065" name="l00065"></a><span class="lineno">   65</span>                      cudaError_t code, <span class="keyword">const</span> <span class="keywordtype">char</span>* expr)</div>
<div class="line"><a id="l00066" name="l00066"></a><span class="lineno">   66</span>            : std::runtime_error(cudaGetErrorString(code)),</div>
<div class="line"><a id="l00067" name="l00067"></a><span class="lineno">   67</span>              file(file),</div>
<div class="line"><a id="l00068" name="l00068"></a><span class="lineno">   68</span>              line(line),</div>
<div class="line"><a id="l00069" name="l00069"></a><span class="lineno">   69</span>              code(code),</div>
<div class="line"><a id="l00070" name="l00070"></a><span class="lineno">   70</span>              expr(expr) {</div>
<div class="line"><a id="l00071" name="l00071"></a><span class="lineno">   71</span>            format_message();</div>
<div class="line"><a id="l00072" name="l00072"></a><span class="lineno">   72</span>        }</div>
<div class="line"><a id="l00073" name="l00073"></a><span class="lineno">   73</span> </div>
<div class="line"><a id="l00074" name="l00074"></a><span class="lineno">   74</span>        <span class="keyword">const</span> <span class="keywordtype">char</span>* what() <span class="keyword">const</span> <span class="keyword">noexcept</span> <span class="keyword">override</span> {</div>
<div class="line"><a id="l00075" name="l00075"></a><span class="lineno">   75</span>            <span class="keywordflow">return</span> msg.c_str();</div>
<div class="line"><a id="l00076" name="l00076"></a><span class="lineno">   76</span>        }</div>
<div class="line"><a id="l00077" name="l00077"></a><span class="lineno">   77</span> </div>
<div class="line"><a id="l00078" name="l00078"></a><span class="lineno">   78</span>        <span class="keywordtype">void</span> format_message() {</div>
<div class="line"><a id="l00079" name="l00079"></a><span class="lineno">   79</span>            snprintf(buffer, <span class="keyword">sizeof</span>(buffer),</div>
<div class="line"><a id="l00080" name="l00080"></a><span class="lineno">   80</span>                     <span class="stringliteral">&quot;CUDA Exception:\n&quot;</span></div>
<div class="line"><a id="l00081" name="l00081"></a><span class="lineno">   81</span>                     <span class="stringliteral">&quot;\tFile:       %s\n&quot;</span></div>
<div class="line"><a id="l00082" name="l00082"></a><span class="lineno">   82</span>                     <span class="stringliteral">&quot;\tLine:       %d\n&quot;</span></div>
<div class="line"><a id="l00083" name="l00083"></a><span class="lineno">   83</span>                     <span class="stringliteral">&quot;\tError code: %d\n&quot;</span></div>
<div class="line"><a id="l00084" name="l00084"></a><span class="lineno">   84</span>                     <span class="stringliteral">&quot;\tError text: %s\n&quot;</span></div>
<div class="line"><a id="l00085" name="l00085"></a><span class="lineno">   85</span>                     <span class="stringliteral">&quot;\tExpression: %s&quot;</span>,</div>
<div class="line"><a id="l00086" name="l00086"></a><span class="lineno">   86</span>                     file, line, code, std::runtime_error::what(), expr);</div>
<div class="line"><a id="l00087" name="l00087"></a><span class="lineno">   87</span> </div>
<div class="line"><a id="l00088" name="l00088"></a><span class="lineno">   88</span>            msg = buffer;</div>
<div class="line"><a id="l00089" name="l00089"></a><span class="lineno">   89</span>        }</div>
<div class="line"><a id="l00090" name="l00090"></a><span class="lineno">   90</span> </div>
<div class="line"><a id="l00091" name="l00091"></a><span class="lineno">   91</span>    <span class="keyword">private</span>:</div>
<div class="line"><a id="l00092" name="l00092"></a><span class="lineno">   92</span>        <span class="keyword">const</span> <span class="keywordtype">char</span>* file;</div>
<div class="line"><a id="l00093" name="l00093"></a><span class="lineno">   93</span>        <span class="keywordtype">int</span> line;</div>
<div class="line"><a id="l00094" name="l00094"></a><span class="lineno">   94</span>        cudaError_t code;</div>
<div class="line"><a id="l00095" name="l00095"></a><span class="lineno">   95</span>        <span class="keyword">const</span> <span class="keywordtype">char</span>* expr;</div>
<div class="line"><a id="l00096" name="l00096"></a><span class="lineno">   96</span>        <span class="keywordtype">char</span> buffer[1024];</div>
<div class="line"><a id="l00097" name="l00097"></a><span class="lineno">   97</span>        std::string msg;</div>
<div class="line"><a id="l00098" name="l00098"></a><span class="lineno">   98</span>    };</div>
</div>
<div class="line"><a id="l00099" name="l00099"></a><span class="lineno">   99</span>}</div>
<div class="line"><a id="l00100" name="l00100"></a><span class="lineno">  100</span> </div>
<div class="line"><a id="l00101" name="l00101"></a><span class="lineno">  101</span><span class="preprocessor">#define CHECK(call)                                                             \</span></div>
<div class="line"><a id="l00102" name="l00102"></a><span class="lineno">  102</span><span class="preprocessor">do {                                                                            \</span></div>
<div class="line"><a id="l00103" name="l00103"></a><span class="lineno">  103</span><span class="preprocessor">cudaError_t __err = call;                                                   \</span></div>
<div class="line"><a id="l00104" name="l00104"></a><span class="lineno">  104</span><span class="preprocessor">if (__err != cudaSuccess) {                                                 \</span></div>
<div class="line"><a id="l00105" name="l00105"></a><span class="lineno">  105</span><span class="preprocessor">cudaDeviceReset();                                                      \</span></div>
<div class="line"><a id="l00106" name="l00106"></a><span class="lineno">  106</span><span class="preprocessor">throw nz::CudaException(__FILE__, __LINE__, __err, #call);                  \</span></div>
<div class="line"><a id="l00107" name="l00107"></a><span class="lineno">  107</span><span class="preprocessor">}                                                                           \</span></div>
<div class="line"><a id="l00108" name="l00108"></a><span class="lineno">  108</span><span class="preprocessor">} while (0)</span></div>
<div class="line"><a id="l00109" name="l00109"></a><span class="lineno">  109</span> </div>
<div class="line"><a id="l00110" name="l00110"></a><span class="lineno">  110</span><span class="preprocessor">#define CHECK_LAST()                                                            \</span></div>
<div class="line"><a id="l00111" name="l00111"></a><span class="lineno">  111</span><span class="preprocessor">do {                                                                            \</span></div>
<div class="line"><a id="l00112" name="l00112"></a><span class="lineno">  112</span><span class="preprocessor">cudaError_t __err = cudaGetLastError();                                     \</span></div>
<div class="line"><a id="l00113" name="l00113"></a><span class="lineno">  113</span><span class="preprocessor">if (__err != cudaSuccess) {                                                 \</span></div>
<div class="line"><a id="l00114" name="l00114"></a><span class="lineno">  114</span><span class="preprocessor">cudaDeviceReset();                                                      \</span></div>
<div class="line"><a id="l00115" name="l00115"></a><span class="lineno">  115</span><span class="preprocessor">throw nz::CudaException(__FILE__, __LINE__, __err, &quot;cudaGetLastError()&quot;);   \</span></div>
<div class="line"><a id="l00116" name="l00116"></a><span class="lineno">  116</span><span class="preprocessor">}                                                                           \</span></div>
<div class="line"><a id="l00117" name="l00117"></a><span class="lineno">  117</span><span class="preprocessor">} while (0)</span></div>
<div class="line"><a id="l00118" name="l00118"></a><span class="lineno">  118</span> </div>
<div class="line"><a id="l00119" name="l00119"></a><span class="lineno">  119</span><span class="preprocessor">#endif</span></div>
<div class="line"><a id="l00120" name="l00120"></a><span class="lineno">  120</span><span class="preprocessor">#endif </span><span class="comment">//NEUZEPHYRCUDAERRORHANDLING_CUH</span></div>
<div class="ttc" id="aclassnz_1_1_cuda_exception_html"><div class="ttname"><a href="classnz_1_1_cuda_exception.html">nz::CudaException</a></div><div class="ttdoc">A final class that represents CUDA exceptions, inheriting from std::runtime_error.</div><div class="ttdef"><b>Definition</b> <a href="#l00062">NeuZephyrCudaErrorHandling.cuh:62</a></div></div>
</div><!-- fragment --></div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated by&#160;<a href="https://www.doxygen.org/index.html"><img class="footer" src="doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.12.0
</small></address>
</div><!-- doc-content -->
</body>
</html>
